package com.jy.bo.common.conf.config;

import com.alibaba.fastjson.JSONObject;
import com.fqgj.common.utils.StringUtils;
import com.google.common.collect.Lists;
import com.jy.bo.common.conf.config.service.ApplicationConfig;
import com.jy.bo.common.conf.util.IpUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: binary
 * Date: 2020/4/29
 * Time: 下午2:16
 */
@Component
public class RedisConfigUtil extends ApplicationConfig {

    private static final String namespace = "bo-api";

    public String getProperty(String key, String defaultValue) {
        return getProperty(namespace, key, defaultValue);
    }

    public Integer getIntProperty(String key, Integer defaultValue) {
        return getIntProperty(namespace, key, defaultValue);
    }

    public Boolean getBooleanProperty(String key, Boolean defaultValue) {
        return getBooleanProperty(namespace, key, defaultValue);
    }

    public int getMinWithdrawalAmount() {
        return getIntProperty("min.withdrawal.amount", 1);
    }

    public int getMaxWithdrawalAmount() {
        return getIntProperty("max.withdrawal.amount", 2000);
    }

    public String getWithdrawPageTips() {
        return getProperty("withdraw.page.tips", "grants cannot be withdrawn");
    }

    /**
     * 充值金额 产品列表
     */
    public String getDepositAmountProductList() {
        String arrStr = "[\n" +
                "    {\n" +
                "        \"code\":\"0CNW8H8T6SCD\",\n" +
                "        \"amount\":10,\n" +
                "        \"grants\":0\n" +
                "    },\n" +
                "    {\n" +
                "        \"code\":\"code500\",\n" +
                "        \"amount\":500,\n" +
                "        \"grants\":0\n" +
                "    },\n" +
                "    {\n" +
                "        \"code\":\"code1000\",\n" +
                "        \"amount\":1000,\n" +
                "        \"grants\":0\n" +
                "    },\n" +
                "    {\n" +
                "        \"code\":\"code2000\",\n" +
                "        \"amount\":2000,\n" +
                "        \"grants\":0\n" +
                "    },\n" +
                "    {\n" +
                "        \"code\":\"code3000\",\n" +
                "        \"amount\":3000,\n" +
                "        \"grants\":0\n" +
                "    },\n" +
                "    {\n" +
                "        \"code\":\"code5000\",\n" +
                "        \"amount\":5000,\n" +
                "        \"grants\":0\n" +
                "    }\n" +
                "]";
//        String property = getProperty("deposit.amount.list", arrStr);
//        return property;
        return arrStr;
    }

    public String getDepositStatusConfig() {
        String arrStr = "[\n" +
                "        {\n" +
                "            \"status\": -1,\n" +
                "            \"icon\": \"https://cm-binary.oss-ap-south-1.aliyuncs.com/img/payment%20confimation%E5%A4%87%E4%BB%BD.png\",\n" +
                "            \"title\": \"Payment Failed\",\n" +
                "            \"tips\": \"\",\n" +
                "            \"buttonText\": \"Retry\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"status\": 1,\n" +
                "            \"icon\": \"https://cm-binary.oss-ap-south-1.aliyuncs.com/img/payment%20confimation%E5%A4%87%E4%BB%BD%202.png\",\n" +
                "            \"title\": \"Payment Processing\",\n" +
                "            \"tips\": \"It may be due to a delay in the bank or wallet, and you need to wait for a period of time to confirm whether the payment is successful.\",\n" +
                "            \"buttonText\": \"OK\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"status\": 2,\n" +
                "            \"icon\": \"https://cm-binary.oss-ap-south-1.aliyuncs.com/img/payment%20confimation.png\",\n" +
                "            \"title\": \"Payment Successful\",\n" +
                "            \"tips\": \"\",\n" +
                "            \"buttonText\": \"Return\"\n" +
                "        }\n" +
                "]";
        return getProperty("deposit.status.config", arrStr);
    }

    public String getPayBaseUrl() {
        //return getProperty("pay.base.url", "http://149.129.179.162:8111/");
        return getProperty("pay.base.url", "https://cash-pay.cashmama.in/");
    }

    public String getRazorpayType() {
        return getProperty("razorpay.type", "WAP");
    }

    public String getInstaMojoType() {
        return getProperty("instaMojo.type", "APP");
    }

    public String getProductCategory() {
        return getProperty("product.category", "binaryOptionAll");
    }

    public String getDomainUrl() {
        return getProperty("domain.url", "https://app-api.abctradeapp.com/");
    }

    public String getGooglePlayUrl() {
        return getProperty("binary.google.play.url", "https://play.google.com/store/apps/details?id=com.abctrade.app");
    }

    /**
     * 全局涨设置
     */
    public Integer getOddsGlobalUpSettingValue() {
        Integer defaultValue = 70;
        return getIntProperty("odds.global.up.value", defaultValue);
    }

    /**
     * 全局涨设置
     */
    public String getOddsGlobalSettingValue() {
        String defaultValue = "{\n" +
                "   \n" +
                "    \"chartTimeRange\":[\n" +
                "        {\n" +
                "            \"name\":\"1H\",\n" +
                "            \"value\":3600,\n" +
                "            \"unitType\":1,\n" +
                "            \"orderId\":1,\n" +
                "            \"defaultShow\":0\n" +
                "        },\n" +
                "        {\n" +
                "            \"name\":\"30M\",\n" +
                "            \"value\":1800,\n" +
                "            \"orderId\":2,\n" +
                "            \"unitType\":2,\n" +
                "            \"defaultShow\":0\n" +
                "        },\n" +
                "        {\n" +
                "            \"name\":\"15M\",\n" +
                "            \"value\":900,\n" +
                "            \"orderId\":3,\n" +
                "            \"unitType\":2,\n" +
                "            \"defaultShow\":0\n" +
                "        },\n" +
                "        {\n" +
                "            \"name\":\"3M\",\n" +
                "            \"value\":180,\n" +
                "            \"orderId\":4,\n" +
                "            \"unitType\":2,\n" +
                "            \"defaultShow\":1\n" +
                "        }\n" +
                "    ],\n" +
                "    \"orderTimeRange\":[\n" +
                "         {\n" +
                "            \"name\":\"1M\",\n" +
                "            \"value\":60,\n" +
                "            \"unitType\":1,\n" +
                "            \"orderId\":1,\n" +
                "            \"defaultShow\":1\n" +
                "        }],\n" +
                "    \"moneyLimit\":{ \n" +
                "        \"min\":20,\n" +
                "        \"max\":2000,\n" +
                "        \"defaultValue\":50,\n" +
                "        \"stepLength\":10\n" +
                "    },\n" +
                "    \"isAutoOrderSwitchOpen\": 0,\n" +
                "    \"coinType\":0\n" +
                "}\n";
        return getProperty("odds.global.setting.value", defaultValue);
    }

    public String getOddsGlobalMoneySetting() {
        String defaultValue = "{ \"min\":20, \"max\":100, \"defaultValue\":50, \"stepLength\":10 }";
        return getProperty("odds.global.money.limit.setting", defaultValue);
    }

    /**
     * 全局跌设置
     */
    public Integer getOddsGlobalDownSettingValue() {
        Integer defaultValue = 70;
        return getIntProperty("odds.global.down.value", defaultValue);
    }


    /**
     * 注册协议
     *
     * @return
     */
    public String getRegisterProtocol() {
        return "http://oss.loanshield.in/agreement/agreement.html";
//        return getProperty("binary.register.protocol", "http://oss.loanshield.in/agreement/agreement.html");
    }

    /**
     * 获取消息服务器地址
     *
     * @return
     */
    public String getMessageHost() {
        return getProperty("message.api.url", "http://149.129.180.244:8112");
    }

    public String getFaqMoreUrl() {
        return getProperty("faq.more.url", "http://oss.loanshield.in/agreement/FAQS.html");
    }

    public String getFaqStr() {
        return getProperty("faq.str", "[\n" +
                "            {\n" +
                "                \"title\":\"When will this money be deducted from the balance?\",\n" +
                "                \"body\":\"When you apply for a withdrawal, the withdrawal part will be frozen (deducted). After the approval, the funds will be withdrawn to the bank you provide. If the verification fails, the funds will be unfrozen and returned to your account.\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"title\":\"When does the withdrawal arrive?\",\n" +
                "                \"body\":\"In general, 90% of applications will be processed within 24 hours or the second working day. The maximum withdrawal period will not exceed 5 working days;\"\n" +
                "            }\n" +
                "        ]");
    }

    /**
     * 同时订单量控制
     *
     * @return
     */
    public Integer getOrdersQuantityLimit() {
        return getIntProperty("orders.quantity.limit", 15);
    }

    public Boolean getOpenRecharge() {
        return getBooleanProperty("open.recharge", false);
    }

    public int getRechargeVersioncode() {
        return getIntProperty("open.recharge.versioncode", 3);
    }

    public Boolean getOpenWithdrawal() {
        return getBooleanProperty("open.withdrawal", false);
    }

    public String getWebSocketHost() {
        return getProperty("socket.web.url", "http://172.31.56.52:9001");
    }

    public String getWebSocketHostNew() {
//        return getProperty("socket.web.url.new", "http://47.117.114.25:80:8099");
        return "http://3.109.65.255:9002";
    }

    public String getWebSocketServerHost() {
        return "ws://3.109.65.255:9001/ws";
//        return getProperty("socket.wss.url", "");
    }

    public String getTaskIp() {
        return getProperty("task.ip", IpUtils.getIp());
    }

    public boolean isNewMarketData() {
        return getBooleanProperty("new.market.data.switch", true);
    }

    /**
     * 使用虚拟账户计算收益率
     *
     * @return
     */
    public boolean calculateOddsByVirtualAccount() {
        return getBooleanProperty("calculate.odds.virtual.account", false);
    }

    /**
     * 引导注册交易提醒的笔数限制
     *
     * @return
     */
    public String guideRealTradeNumbers() {
        return getProperty("guide.real.numbers", "10,30,50");
    }


    public String getUpdateDesc() {
        return getProperty("android.update.desc", "Bug fix;\nEnhance customer experience.");
    }

    public Integer getMiniAndroidVersionCode() {
        return 1;
//        return getIntProperty("android.update.mini.version.code", 1);
    }

    public boolean openForceUpdate() {
        return getBooleanProperty("force.update.open", false);
    }

    public boolean isTest() {
        return getBooleanProperty("is.test", false);
    }

    public boolean marketOddsTaskOpen() {
        return getBooleanProperty("market.odds.task.open", false);
    }

    /**
     * >该点 初始化大盘收益率
     *
     * @return
     */
    public Integer getMaxPlatformProfitPct() {
        return getIntProperty("max.platform.profit.pct", 15);
    }

    /**
     * 大盘变动生效阈值
     *
     * @return
     */
    public Integer getChangeOddsTradeNumbers() {
        return getIntProperty("change.odds.trade.numbers", 20);
    }

    /**
     * 用户变动生效阈值
     *
     * @return
     */
    public Integer getChangeOddsUserTradeNumbers() {
        return getIntProperty("change.odds.user.trade.numbers", 10);
    }

    public Integer getInviteBonus() {
        return getIntProperty("invite.bonus", 30);
    }

    public List<String> getIntroduction() {
        String introduction = getProperty("invite.introduction", "");
        if (StringUtils.isEmpty(introduction)) {
            return Lists.newArrayList();
        }
        return JSONObject.parseArray(introduction, String.class);
    }

    public String getInviteUrl() {
        return getProperty("invite.h5.url", "");
    }

    public String getActivityImgUrl() {
        return getProperty("activity.img.url", "https://oss.abctradeapp.com/img/deposit_activity.png");
    }

    public String getBanners() {
        return getProperty("trade.banners", "[\n" +
                "    {\n" +
                "        \"imgUrl\":\"https://oss.abctradeapp.com/img/invite_friends_fk.png\",\n" +
                "        \"redirectUrl\":\"URL/inviteFriends\"\n" +
                "    }\n" +
                "]");
    }

    public Integer firstDepositGrants() {
        return getIntProperty("first.deposit.grants", 0);
    }

    public String getUserAuthPageTips() {
        return getProperty("user.auth.page.tips", "We will create a AbcTrade account for you to first deposit");
    }

    public boolean getUserAuthPageSwitch() {
        return getBooleanProperty("user.auth.page.tips", false);
    }

    public Integer deviceIdNumber() {
        return getIntProperty("device.id.number", 3);
    }

    public Integer delaySeconds() {
        return getIntProperty("delay.seconds", 10);
    }

    /**
     * 灰名单满足条件
     *
     * @return
     */
    public String getProfitIntervalValue() {
        String defaultValue = "[{\n" +
                "        \"lower\":100,\n" +
                "        \"upper\":300,\n" +
                "        \"multiple\":8\n" +
                "    },{\n" +
                "        \"lower\":300,\n" +
                "        \"upper\":600,\n" +
                "        \"multiple\":5\n" +
                "    },{\n" +
                "        \"lower\":600,\n" +
                "        \"upper\":1300,\n" +
                "        \"multiple\":2\n" +
                "    },{\n" +
                "        \"lower\":1300,\n" +
                "        \"upper\":5000,\n" +
                "        \"multiple\":1\n" +
                "    },{\n" +
                "        \"lower\":5000,\n" +
                "        \"upper\":10000,\n" +
                "        \"multiple\":0.6\n" +
                "    },{\n" +
                "        \"lower\":10000,\n" +
                "        \"upper\":9999999999,\n" +
                "        \"multiple\":0.4\n" +
                "    }]";
        return getProperty("profit.interval.value", defaultValue);
    }
}
